// 登录
function signin(obj,url) {
    obj = $(obj);
    var umobile = obj.parent().find('input[name=mobile]').val();
    var  upassword= obj.parent().find('input[name = password]').val();
    $.post(
        url,
        {
            'mobile' : umobile,
            'password' : upassword
        },
        function(data){
            layer.msg(data.msg);
            if (data.code) {
                setTimeout(function () {
                    history.go(0);
                }, 1000);
            }
        }
    );
    return false;
}
    
// 退出
function signout(obj,url) {
    $.post(url,function(data) {
        layer.msg(data.msg);
        if (data.code) {
            setTimeout(function () {
                history.go(0);
            },1000);
        }
    });
    return false;
}

// 验证码刷新
function verifyimg(url) {
    $(".verifyimg").attr("src",url);
}

// 注册
function signup(obj,url) {
    obj = $(obj)
    var umobile = obj.parents('.rgerster').find('input[name=mobile]').val();
    var code = obj.parents('.rgerster').find('input[name=code]').val();
    var pwd = obj.parents('.rgerster').find('input[name=password]').val();
    var rpwd = obj.parents('.rgerster').find('input[name=rpwd]').val();
    var read = obj.parents('.rgerster').find('input[name=read]').val();
    var pmobile = obj.parents('.rgerster').find('input[name=pmobile]').val();
    var QQaccount = obj.parents('.rgerster').find('input[name=QQaccount]').val();
    if (read == 'Y') {
        if (code) {
            if (pwd == rpwd){
                $.post(
                    url,
                    {
                        'mobile' : umobile,
                        'password' : pwd,
                        'rpwd' : rpwd,
                        'code' : code,
                        'pmobile' : pmobile,
                        'QQaccount' : QQaccount
                    },
                    function(data){
                        layer.msg(data.msg);
                        setTimeout(function () {
                            history.go(0);
                        },1000);
                    }
                );
            } else {
                layer.msg('两次密码不一致');
            }
        }
        layer.msg('短信验证码不可为空')
    } else {
        layer.msg('请阅读服务协议');
    }
}

var countdown=60;
// 获取短信
function code (obj,url,imgsrc) {
    var ob = $(obj);
    var umobile = ob.parents('.rgerster').find('input[name=mobile]').val();
    var verify = ob.parents('.rgerster').find('input[name=verify]').val();
    $.post(
        url,
        {
            'mobile':umobile,
            'verify':verify
        },
        function(data){
            if (data.code) {
                settime(obj);
            }else{
                verifyimg(imgsrc);
                layer.msg(data.msg);
            }
        }
    );
}
function codes (obj,url) {
    var ob = $(obj);
    var umobile = ob.parents('.forget').find('input[name=mobile]').val();
    if(!umobile){
        layer.msg('手机号不可为空');
        return false;
    }
    $.post(
        url,
        {
            'mobile':umobile
        },
        function(data){
            if (data.code) {
                settime(obj);
            }else{
                layer.msg(data.msg);
            }
        }
    );
}

function forget(obj,url) {
    var ob = $(obj);
    var umobile = ob.parents('.forget').find('input[name=mobile]').val();
    var code = ob.parents('.forget').find('input[name=code]').val();
    var pwd = ob.parents('.forget').find('input[name=pwd]').val();
    var rpwd = ob.parents('.forget').find('input[name=rpwd]').val();
    if(!pwd){
        layer.msg('密码不可为空');
        return false;
    }
    if(!code){
        layer.msg('验证码不可为空');
        return false;
    }
    if (pwd == rpwd) {
        $.post(
            url,
            {
                'mobile': umobile,
                'code' :code,
                'password' : pwd
            },
            function(data){
                if (data.code) {
                    settime(obj);
                }else{
                    layer.msg(data.msg);
                }
            }
        );
    } else {
        layer.msg('两次密码不一致');
    }
        return false;
}

// 计时器
function settime(obj) {
    var ob = $(obj);
  if (countdown == 0) {
    obj.removeAttribute("disabled");
    obj.value="获取验证码";
    countdown = 60;
    return;
  } else {
    obj.setAttribute("disabled", true);
    obj.value="重新发送(" + countdown + ")";
    countdown--;
  }
setTimeout(function() {
  settime(obj) }
  ,1000)
}

$(function(){
	//导航的切换
var oHomePage_li = $('.homePage_nav>li')
            $('.homePage_nav>li').click(function() {
            var aaa = $(this).index();
            sessionStorage.setItem('key', aaa);
        });
        var a = sessionStorage.getItem('key');
        console.log(a)
        if(a) {
           $('.homePage_nav>li').eq(a).addClass("nav_active").siblings().removeClass("nav_active");
           
            if(a!=0){
            
            $('.homePage_nav>li').eq(0).removeClass("nav_active");
                
            }
        }

     //app下载//红包//信
   var aClick_btn = $('.app_red_letter_btn');
    var app_r_l = $('.app_packet_letter');
    var red = $('red_envelop');
    var oOpen_box = $('.open_box');
    // app_r_l.hide();
//  var top=[0,1100,1100,1100]
       $.each(aClick_btn, function(index,value) {
        
        $(this).click(function(){
            oOpen_box.show();
            app_r_l.eq(index).show().siblings().hide();
            return false;
        })
       });
     // $(document).click(function(){
     //    app_r_l.css({'display':'none'});
     //    
     // })
     $('.red_envelop').click(function(){
        $.post('/index/index/redenve',function(data){
            layer.msg(data.msg);
            $(this).parent().css('display','none');
            oOpen_box.hide();
            // setTimeout(function () {
            //     history.go(0);
            // },1000);
        });
     })
     $('.inner_letter .cancel').click(function(){
        $(this).parent().css('display','none');
        oOpen_box.hide();
     })
  
   var oBtn_service = $('.btn_service');
   var oBtn_cancel = $('.click_delit');
   var oService = $('.service');
   oBtn_service.click(function(){
    oService.show();
   })
   oBtn_cancel.click(function(){
    oService.hide();
   })




})


